--- import type { GetStaticPaths } from 'astro'; import { getCollection } from 'astro:content'; import { siteConfig } from '@/config'; import { generatePageSEO } from '@/utils/seo'; import { shouldShowPost, sortPostsByDate, extractTags } from '@/utils/markdown'; import BaseLayout from '@/layouts/BaseLayout.astro'; import PostCard from '@/components/PostCard.astro'; import Tags from '@/components/Tags.astro'; import Pagination from '@/components/Pagination.astro'; import Icon from '@/components/Icon.astro'; export const getStaticPaths: GetStaticPaths = async () => { // Get all posts const allPosts = await getCollection('posts'); // Filter posts based on environment const isDev = import.meta.env.DEV; const visiblePosts = allPosts.filter(post => shouldShowPost(post, isDev)); // Sort posts by date const sortedPosts = sortPostsByDate(visiblePosts); // Calculate total pages const postsPerPage = siteConfig.postOptions.postsPerPage; const totalPages = Math.ceil(sortedPosts.length / postsPerPage); // Generate paths for each page (starting from page 2) const paths = []; for (let page = 2; page <= totalPages; page++) { paths.push({ params: { page: page.toString() }, props: { posts: sortedPosts, currentPage: page, totalPages, postsPerPage } }); } return paths; }; export interface Props { posts: any[]; currentPage: number; totalPages: number; postsPerPage: number; } const { posts, currentPage, totalPages, postsPerPage } = Astro.props; // Get query parameters const url = new URL(Astro.request.url); const selectedTag = url.searchParams.get('tag'); // Filter by tag if specified const filteredPosts = selectedTag ? posts.filter(post => post.data.tags?.includes(selectedTag)) : posts; // Calculate pagination for current page const startIndex = (currentPage - 1) * postsPerPage; const endIndex = Math.min(startIndex + postsPerPage, filteredPosts.length); const paginatedPosts = filteredPosts.slice(startIndex, endIndex); // Extract all unique tags const allTags = extractTags(posts); // Generate SEO data const pageTitle = selectedTag ? `Posts tagged "${selectedTag}" - Page ${currentPage}` : `All Posts - Page ${currentPage}`; const pageDescription = selectedTag ? `Page ${currentPage} of posts tagged with "${selectedTag}"` : `Page ${currentPage} of all posts on ${siteConfig.title}`; const seoData = { title: `${pageTitle} | ${siteConfig.title}`, description: pageDescription, canonical: Astro.url.href, ogType: 'website' as const }; // Pagination info const pagination = { currentPage, totalPages, hasNext: currentPage < totalPages, hasPrev: currentPage > 1, nextUrl: currentPage < totalPages ? `/posts/${currentPage + 1}` : undefined, prevUrl: currentPage > 2 ? `/posts/${currentPage - 1}` : '/posts' }; ---

{selectedTag ? ( <>Posts tagged "{selectedTag}" ) : ( <>All Posts )}

Page {currentPage} of {totalPages} • {filteredPosts.length} {selectedTag ? ( <>posts tagged with #{selectedTag} ) : ( <>total posts )}

{paginatedPosts.length > 0 ? ( <>
{paginatedPosts.map((post, index) => ( ))}
) : (

No posts found on this page

Try going back to an earlier page or removing filters.

View All Posts {currentPage > 1 && ( Previous Page )}
)}
{siteConfig.postOptions.tags && allTags.length > 0 && ( )}